begintownscript;

variables;
short bmessage,leadchar,pcs,count,rctx,rcty,terr_typ,odds_hit,trgt_ddg;
short bless,haste_amt,countdwn;
string custom_m;

body;

beginstate INIT_STATE;

	set_total_visibility(1);
	leadchar = 0;
	while(char_ok(leadchar) == 0){
		leadchar = (leadchar + 1);
	}
	relocate_character(leadchar,16,17);
	force_view_center(16,17);
	set_character_facing(leadchar,get_ran(1,0,7));
	pcs = (leadchar + 1);
	count = 0;
	while(pcs <= 3){
		if(char_ok(pcs) == TRUE){
			if(count == 0)
				relocate_character(pcs,14,19);
			if(count == 1)
				relocate_character(pcs,19,18);
			if(count == 2)
				relocate_character(pcs,17,19);
			set_character_facing(pcs,get_ran(1,0,7));

			count = (count + 1);
		}
		pcs = (pcs + 1);
	}

	force_instant_terrain_redraw();
	pause(2);

	count = 0;
	while(count <= 3){
		rctx = 10;
		while(rctx <= 22){
			rcty = 10;
			while(rcty <= 22){
				terr_typ = get_terrain(rctx,rcty);
				if((terr_typ >= 175) && (terr_typ <= 177))
set_terrain(rctx,rcty,get_ran(1,175,177));

				rcty = (rcty + 1);
			}

			rctx = (rctx + 1);
		}
		force_instant_terrain_redraw();
		pause(2);

		count = (count + 1);
	}

	reset_dialog();
	if(get_flag(64,0) == 0)
		add_dialog_str(0,"The mysterious figure had best be right about an elastic barrier...  If he's not, it's unlikely that--",0);
	else
		add_dialog_str(0,"_K_ had best be right about an elastic barrier...  If he's not, it's unlikely that--",0);
	add_dialog_str(1,"What the hell is that?!",40);
	add_dialog_str(2,"Incoming!  It looks familiar, too!  But it can't be...",0);
	add_dialog_choice(0,"The sniper?!");
	bmessage = run_dialog(1);

//	set_floor(16,19,255);
//	set_floor(16,20,255);
//	set_floor(17,19,255);
//	set_height(16,19,10);

	force_view_center(16,13);
	set_character_facing(1000,0);
	activate_hidden_group(1);
	set_terrain(16,13,271);
	force_instant_terrain_redraw();
	pause(1);

	set_terrain(16,13,287);
	force_instant_terrain_redraw();
	pause(1);

	set_terrain(16,13,288);
	force_instant_terrain_redraw();
	pause(1);

	set_terrain(16,13,340);
	force_instant_terrain_redraw();
	pause(1);

	set_terrain(16,13,359);
	force_instant_terrain_redraw();
	pause(1);

	set_terrain(16,13,177);
	force_instant_terrain_redraw();
	pause(1);

	text_bubble_on_char(6,"DIE!");
	set_character_pose(6,1);
//	pcs = random_party_member();
	pcs = 0;
	while(char_ok(pcs) == FALSE){
		pcs = (pcs + 1);
	}
	put_straight_zap(16,13,char_loc_x(pcs),char_loc_y(pcs),0);
	put_boom_on_space(char_loc_x(pcs),char_loc_y(pcs),1,0);
	force_instant_terrain_redraw();
	run_animation_sound(5);
	trgt_ddg = (get_stat(pcs,1) + get_ran(get_stat(pcs,9),0,1));
	trgt_ddg = (trgt_ddg + get_stat(pcs,18));
	trgt_ddg = (trgt_ddg + get_stat(pcs,23));
	bless = (get_char_status(pcs,1));
	if(bless > 5)
		bless = 5;
	if(bless < -5)
		bless = -5;
	trgt_ddg = (trgt_ddg + bless);
	odds_hit = (22 - trgt_ddg);
	if(odds_hit <= 0)
		odds_hit = 1;
	if(odds_hit >= 20)
		odds_hit = 19;
	if(odds_hit >= get_ran(1,1,20)){
		print_big_str("Immortal hits (",(odds_hit * 5),"%).");
		damage_char(pcs,get_ran((18 - bless),1,5),0);
		damage_char(pcs,20,1);
	}
	else{
		print_big_str("Immortal misses (",(odds_hit * 5),"%).");
	}
	pause(6);
	set_character_pose(6,0);
	text_bubble_on_char(6,"");
	force_instant_terrain_redraw();

	reset_dialog();
	add_dialog_str(0,"_I am called 'The Immortal'.  Know this as you perish!_",0);
	add_dialog_str(1,"He doesn't mince words.",0);
	add_dialog_str(2," ",0);
	add_dialog_str(3,"(Haste spells will have no effect in this environment)",0);
	add_dialog_choice(0,"Let's go.");
	bmessage = run_dialog(1);

//	set_floor(16,19,161);
//	set_floor(16,20,161);
//	set_floor(17,19,161);
//	set_floor(17,20,161);

break;

beginstate START_STATE;

	if(countdwn < 15)
		countdwn = (countdwn + 1);
	if(countdwn == 15){
		reset_dialog();
		if(party_size() == 1)
			add_dialog_str(0,"The combat between The Immortal and me is raging, but a faintly glowing, sky-blue floor is rapidly approaching.  Looks like we're about to hit bottom...",0);
		if(party_size() > 1)
			add_dialog_str(0,"The combat between The Immortal and us is raging, but a faintly glowing, sky-blue floor is rapidly approaching.  Looks like we're about to hit bottom...",0);
		add_dialog_str(1," ",0);
		add_dialog_str(2,"(End combat and move in any direction)",0);
		add_dialog_choice(0,"Time to pray.");
		bmessage = run_dialog(1);
		erase_char(6);
		set_flag(75,0,1);
		countdwn = 16;
	}
	if((get_flag(75,0) == 1) && (is_combat() == FALSE)){
		set_total_visibility(0);
		teleport_party(7,7,1);
	}
	rctx = 10;
	while(rctx <= 22){
		rcty = 10;
		while(rcty <= 22){
			terr_typ = get_terrain(rctx,rcty);
			if((terr_typ >= 175) && (terr_typ <= 177))
				set_terrain(rctx,rcty,get_ran(1,175,177));
			move_item_on_spot(rctx,rcty,-1,-1);

			rcty = (rcty + 1);
		}

		rctx = (rctx + 1);
	}
	force_instant_terrain_redraw();

	pcs = 0;
	while(pcs <= 3){
		if(char_ok(pcs) == TRUE){
			haste_amt = get_char_status(pcs,3);
			if(haste_amt > 0)
				set_char_status(pcs,3,(haste_amt * -1),1,0);
		}

		pcs = (pcs + 1);
	}

break;

beginstate EXIT_STATE;
break;

break;

beginstate 10;

	move_to_new_town(16,16,16);

break;

